package com.woniuxy.article.service.impl;

import com.hc.entity.Comment;
import com.woniuxy.article.mapper.CommentMapper;
import com.woniuxy.article.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/10/20 15:11
 */
@Service("commentService")
public class CommentServiceImpl implements CommentService {
    @Autowired
    CommentMapper commentMapper;

    @Override
    public void addComment(Comment commnet) {
        commnet.setStatus("n");
        commnet.setUnlikenum(0);
        commnet.setLikenum(0);
        commentMapper.addCommentByPaperIdAndComentId(commnet);
    }

    /**
     * 点赞
     * @param commnet
     */
    @Override
    public void updateAgreenum(Comment commnet) {
        //待续....并发问题
        int likeNum = commentMapper.getLikeNum(commnet.getId());
        commnet.setLikenum(likeNum+1);
        commentMapper.updateCommentAgreeByComentId(commnet);
    }

    /**
     * 踩
     * @param commnet
     */
    @Override
    public void updatedisAgreenum(Comment commnet) {
        //待续....并发问题
        int unlikeNum = commentMapper.getDisLikeNum(commnet.getId());
        commnet.setUnlikenum(unlikeNum+1);
        commentMapper.updateCommentdisAgreeByComentId(commnet);
    }

    /**
     * 评论置顶
     * @param commnet
     */
    @Override
    public void setTop(Comment commnet) {
        //现将相应的文章所用评论变为非置顶
        commentMapper.setdown(commnet.getPaper().getId());
        //将该评论变为置顶
        commentMapper.setTop(commnet.getId());

    }


}
